package lagou;


import lagou.bean.ConsumerComponent;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;


public class AnnotationConsumerMain {
    public static void main(String ip) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        ConsumerComponent service = context.getBean(ConsumerComponent.class);
        while (true) {
            Thread.sleep(2000);
          //  System.in.read();

                String hello = service.sayHello("world", 0);
                System.out.println("result :" + hello);

            RpcContext.getContext().setAttachment("serverIP", ip);

               // String serverIP = RpcContext.getContext().getRemoteHost();
                System.out.println("serverIP=="+ip);

        }
    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    //@EnableDubbo(scanBasePackages = "com.lagou.bean")
    @ComponentScan("lagou.bean")
    @EnableDubbo
    static class ConsumerConfiguration {

    }
}
